load("//bazel:mongo_src_rules.bzl", "idl_generator", "mongo_cc_library", "mongo_cc_unit_test")

package(default_visibility = ["//visibility:public"])

exports_files(
    glob([
        "*.h",
        "*.cpp",
    ]),
)

idl_generator(
    name = "timeseries_gen",
    src = "timeseries.idl",
    hdrs = [
        "//src/mongo/db/timeseries:timeseries_global_options.h",
    ],
    deps = [
        "//src/mongo/db:basic_types_gen",
    ],
)

mongo_cc_library(
    name = "timeseries_options",
    srcs = [
        "timeseries_gen",
        "timeseries_global_options.cpp",
        "timeseries_options.cpp",
    ],
    hdrs = [
        "timeseries_global_options.h",
        "timeseries_options.h",
    ],
    deps = [
        "//src/mongo/db:server_base",
        "//src/mongo/db/query/query_shape",  # TODO(SERVER-93876): Remove.
        "//src/mongo/db/storage:storage_options",
        "//src/mongo/util:processinfo",
    ],
)

mongo_cc_library(
    name = "timeseries_extended_range",
    srcs = [
        "timeseries_constants.h",
        "timeseries_extended_range.cpp",
        "//src/mongo/db/commands:create_command_validation.h",
    ],
    hdrs = [
        "timeseries_extended_range.h",
    ],
    deps = [
        ":timeseries_options",  # TODO(SERVER-93876): Remove.
        "//src/mongo:base",
        "//src/mongo/db/catalog:index_catalog",
    ],
)

mongo_cc_library(
    name = "timeseries_metadata",
    srcs = [
        "metadata.cpp",
    ],
    hdrs = [
        "metadata.h",
    ],
    deps = [
        "//src/mongo:base",
    ],
)

mongo_cc_library(
    name = "bucket_compression_failure",
    srcs = [
        "bucket_compression_failure.cpp",
    ],
    hdrs = [
        "bucket_compression_failure.h",
    ],
    deps = [
        "//src/mongo:base",
    ],
)

mongo_cc_library(
    name = "bucket_compression",
    srcs = [
        "bucket_compression.cpp",
    ],
    hdrs = [
        "bucket_compression.h",
        "timeseries_constants.h",
        "timeseries_index_schema_conversion_functions.h",
        "timeseries_options.h",
        "timeseries_write_util.h",
        "//src/mongo/bson:unordered_fields_bsonobj_comparator.h",
        "//src/mongo/db/commands:create_command_validation.h",
        # TODO(SERVER-93876): move these headers under a timeseries bucket catalog target once one is added
        "//src/mongo/db/timeseries/bucket_catalog:bucket.h",
        "//src/mongo/db/timeseries/bucket_catalog:bucket_catalog.h",
        "//src/mongo/db/timeseries/bucket_catalog:bucket_identifiers.h",
        "//src/mongo/db/timeseries/bucket_catalog:bucket_metadata.h",
        "//src/mongo/db/timeseries/bucket_catalog:bucket_state_registry.h",
        "//src/mongo/db/timeseries/bucket_catalog:closed_bucket.h",
        "//src/mongo/db/timeseries/bucket_catalog:execution_stats.h",
        "//src/mongo/db/timeseries/bucket_catalog:flat_bson.h",
        "//src/mongo/db/timeseries/bucket_catalog:measurement_map.h",
        "//src/mongo/db/timeseries/bucket_catalog:reopening.h",
        "//src/mongo/db/timeseries/bucket_catalog:rollover.h",
        "//src/mongo/db/timeseries/bucket_catalog:tracking_contexts.h",
        "//src/mongo/db/timeseries/bucket_catalog:write_batch.h",
        "//src/mongo/db/timeseries/write_ops:measurement.h",
        "//src/mongo/db/catalog:collection.h",
        "//src/mongo/db/catalog:index_catalog.h",
        "//src/mongo/db/catalog:index_catalog_entry.h",
    ],
    header_deps = [
        "//src/mongo/db/commands:server_status_core",
        "//src/mongo/util/tracking",
    ],
    deps = [
        "//src/mongo/bson/column",
        "//src/mongo/db:server_base",
        "//src/mongo/db/collection_crud:capped_visibility",
        "//src/mongo/db/storage:storage_options",
        "//src/mongo/util:fail_point",
    ],
)

mongo_cc_library(
    name = "timeseries_conversion_util",
    srcs = [
        "timeseries_commands_conversion_helper.cpp",
        "timeseries_dotted_path_support.cpp",
        "timeseries_index_schema_conversion_functions.cpp",
        "timeseries_update_delete_util.cpp",
        "//src/mongo/db/matcher:extensions_callback_real.h",
        "//src/mongo/db/pipeline:document_source_coll_stats.h",
        "//src/mongo/db/pipeline:document_source_index_stats.h",
        "//src/mongo/db/pipeline:document_source_internal_convert_bucket_index_stats.h",
        "//src/mongo/db/pipeline:document_source_internal_unpack_bucket.h",
        "//src/mongo/db/query/write_ops:parsed_writes_common.h",
    ],
    hdrs = [
        "timeseries_commands_conversion_helper.h",
        "timeseries_dotted_path_support.h",
        "timeseries_index_schema_conversion_functions.h",
        "timeseries_update_delete_util.h",
    ],
    deps = [
        ":bucket_compression",
        ":timeseries_options",  # TODO(SERVER-93876): Remove.
        "//src/mongo/bson/column",  # TODO(SERVER-93876): Remove.
        "//src/mongo/db:coll_mod_command_idl",  # TODO(SERVER-93876): Remove.
        "//src/mongo/db:index_commands_idl",  # TODO(SERVER-93876): Remove.
        "//src/mongo/db:server_base",
        "//src/mongo/db/catalog:index_catalog",
        "//src/mongo/db/exec:bucket_unpacker",
        "//src/mongo/db/query:bucket_predicate_generator",  # TODO(SERVER-93876): Remove.
        "//src/mongo/db/query/write_ops:write_ops_parsers",  # TODO(SERVER-93876): Remove.
        "//src/mongo/db/storage:storage_options",  # TODO(SERVER-93876): Remove.
    ],
)

mongo_cc_library(
    name = "catalog_helper",
    srcs = [
        "catalog_helper.cpp",
    ],
    hdrs = [
        "catalog_helper.h",
    ],
    deps = [
        ":timeseries_options",
        "//src/mongo/db:server_base",
        "//src/mongo/db/catalog:collection_catalog",
    ],
)

mongo_cc_library(
    name = "timeseries_write_util",
    srcs = [
        "timeseries_write_util.cpp",
        "//src/mongo/db/query:explain.h",
        "//src/mongo/db/query/write_ops:update_request.h",
    ],
    hdrs = [
        "timeseries_write_util.h",
    ],
    deps = [
        ":bucket_compression",
        ":bucket_compression_failure",
        ":timeseries_conversion_util",
        ":timeseries_options",
        "//src/mongo/db:dbdirectclient",
        "//src/mongo/db:record_id_helpers",
        "//src/mongo/db:shard_role",
        "//src/mongo/db/catalog:collection_query_info",
        "//src/mongo/db/catalog:document_validation",
        "//src/mongo/db/collection_crud",
        "//src/mongo/db/query/query_stats",
        "//src/mongo/db/query/write_ops:delete_request_idl",
        "//src/mongo/db/query/write_ops:write_ops_exec_util",
        "//src/mongo/db/storage:storage_options",
        "//src/mongo/db/timeseries/bucket_catalog",
        "//src/mongo/db/timeseries/write_ops:timeseries_write_ops_utils_internal",
        "//src/mongo/db/update:update_common",
    ],
)

mongo_cc_library(
    name = "timeseries_op_observer",
    srcs = [
        "timeseries_op_observer.cpp",
    ],
    hdrs = [
        "timeseries_op_observer.h",
    ],
    deps = [
        ":timeseries_extended_range",
        "//src/mongo/db/catalog:collection_catalog",
        "//src/mongo/db/concurrency:lock_manager",
        "//src/mongo/db/op_observer",
        "//src/mongo/db/timeseries/bucket_catalog",
    ],
)

mongo_cc_library(
    name = "timeseries_collmod",
    srcs = [
        "timeseries_collmod.cpp",
    ],
    hdrs = [
        "timeseries_collmod.h",
    ],
    deps = [
        ":catalog_helper",
        ":timeseries_conversion_util",
        ":timeseries_options",
        "//src/mongo/db:coll_mod_command_idl",
        "//src/mongo/db:index_commands_idl",
        "//src/mongo/db:server_base",
        "//src/mongo/db:shard_role",
        "//src/mongo/db/catalog:catalog_helpers",
        "//src/mongo/db/exec:bucket_unpacker",
    ],
)

mongo_cc_unit_test(
    name = "db_timeseries_test",
    srcs = [
        "bucket_compression_test.cpp",
        "timeseries_dotted_path_support_test.cpp",
        "timeseries_extended_range_test.cpp",
        "timeseries_index_schema_conversion_functions_test.cpp",
        "timeseries_options_test.cpp",
        "timeseries_update_delete_util_test.cpp",
        "timeseries_write_util_test.cpp",
    ],
    tags = ["mongo_unittest_third_group"],
    deps = [
        ":bucket_compression",
        ":timeseries_conversion_util",
        ":timeseries_extended_range",
        ":timeseries_options",
        ":timeseries_write_util",
        "//src/mongo/db:record_id_helpers",
        "//src/mongo/db:shard_role",
        "//src/mongo/db/catalog:catalog_test_fixture",
        "//src/mongo/db/collection_crud",
        "//src/mongo/db/timeseries/bucket_catalog",
        "//src/mongo/idl:server_parameter_test_util",
    ],
)
